function disposeAll(scene) {
  // 深度优先遍历场景对象
  function recursiveDispose(object) {
    if (object.isMesh) {
      // 销毁几何体和材质
      object.geometry.dispose();
      if (object.material.isMaterial) {
        object.material.dispose();
      } else {
        // 材质是数组的情况
        object.material.forEach(material => material.dispose());
      }
    }

    // 销毁子对象
    object.traverse((child) => {
      if (child.isMesh || child.isMaterial || child.isTexture) {
        child.dispose();
      }
    });
  }

  // 销毁所有子对象
  scene.traverse(recursiveDispose);
}

disposeAll(scene);


/* 

*/
{

  /* 
  scene.traverse((object) => {
    if (object.isMesh) {
        if (object.geometry) object.geometry.dispose(); // 释放几何体
        if (object.material) {
            if (Array.isArray(object.material)) {
                object.material.forEach(material => material.dispose()); // 释放多个材质
            } else {
                object.material.dispose(); // 释放单个材质
            }
        }
    }
});

// 最后，调用 renderer.dispose()
renderer.dispose();



 // 销毁
dispose() {
    for (const resource of this.resources) {
        if (resource instanceof THREE.Object3D) {
            if (resource.parent) {
                resource.parent.remove(resource);
            }
        }
        if (resource.dispose) {
            resource.dispose();
        }
    }
    this.resources.clear();
}


// 统一处理所有资源
destroy() {
    // dispose geometry and material
    this.scene.traverse((obj) => {
            if (obj instanceof THREE.Mesh) {
                    obj.geometry.dispose();
                    obj.material.map?.dispose();
                    obj.material.map = null;
                    obj.material.dispose();
            }

            if (obj instanceof THREE.Light) {
                    obj.dispose();
            }
    });
    this.trackManager.dispose();
    // console.log(this.renderer.info.memory);

    // dispose all
    cancelAnimationFrame(this.animationId);
    this.scene.clear();
    this.renderer.renderLists.dispose();
    this.renderer.dispose();
    this.renderer.forceContextLoss();
    this.dom.removeChild(this.renderer.domElement);
    this.dom = null;
    this.renderer.domElement = null;
    this.scene = null;
    this.camera = null;
    this.renderer = null;

    THREE.Cache.clear();
}


function clearThree(obj){
  while(obj.children.length > 0){ 
    clearThree(obj.children[0])
    obj.remove(obj.children[0]);
  }
  if(obj.geometry) obj.geometry.dispose()

  if(obj.material){ 
    //in case of map, bumpMap, normalMap, envMap ...
    Object.keys(obj.material).forEach(prop => {
      if(!obj.material[prop])
        return         
      if(typeof obj.material[prop].dispose === 'function')                                  
        obj.material[prop].dispose()                                                        
    })
    obj.material.dispose()
  }
}   

clearThree(scene)

  */
}